﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace HMI_BR_tech
{
    public partial class FormMain : Form
    {
        List<Form> listfrm;
        public FormMain()
        {
            InitializeComponent();

            frmMajorInterface.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmMajorInterface.TopLevel = false;
            frmMajorInterface.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmMajorInterface);

            frmSystemManagement.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmSystemManagement.TopLevel = false;
            frmSystemManagement.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmSystemManagement);

            frmFuncManagement.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmFuncManagement.TopLevel = false;
            frmFuncManagement.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmFuncManagement);

            frmInfoManagement.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmInfoManagement.TopLevel = false;
            frmInfoManagement.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmInfoManagement);

            frmCalibrationManagement.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmCalibrationManagement.TopLevel = false;
            frmCalibrationManagement.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmCalibrationManagement);

            frmLogManagement.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmLogManagement.TopLevel = false;
            frmLogManagement.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmLogManagement);

            frmStopOperating.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmStopOperating.TopLevel = false;
            frmStopOperating.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmStopOperating);

            frmManualOperating.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmManualOperating.TopLevel = false;
            frmManualOperating.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmManualOperating);

            frmFormulaConfigue.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmFormulaConfigue.TopLevel = false;
            frmFormulaConfigue.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmFormulaConfigue);

            frmMonitorChart.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmMonitorChart.TopLevel = false;
            frmMonitorChart.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmMonitorChart);

            frmProductionChart.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmProductionChart.TopLevel = false;
            frmProductionChart.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmProductionChart);

            frmHelp.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frmHelp.TopLevel = false;
            frmHelp.Dock = System.Windows.Forms.DockStyle.Left;
            this.panelMain.Controls.Add(frmHelp);

            Form[] frminput = {
                frmMajorInterface,
                frmSystemManagement,
                frmFuncManagement,
                frmInfoManagement,
                frmCalibrationManagement,
                frmLogManagement,
                frmStopOperating,
                frmManualOperating,
                frmFormulaConfigue,
                frmMonitorChart,
                frmProductionChart,   
                frmHelp,
            };
            listfrm = new List<Form>(frminput);
            
            frmMajorInterface.Show();

            new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        label_CurTime.BeginInvoke(new MethodInvoker(() =>
                            label_CurTime.Text = DateTime.Now.ToString()));
                    }
                    catch
                    { }
                    Thread.Sleep(1000);
                }
            }) { IsBackground = true }.Start();     
        }

        private void button_MajorInterface_Click(object sender, EventArgs e)
        {
            showSubForm(0);
        }

        private void button_SystemManagement_Click(object sender, EventArgs e)
        {
            showSubForm(1);
            frmSystemManagement.toshow();
        }

        private void button_FuncManagement_Click(object sender, EventArgs e)
        {
            showSubForm(2);
            
        }

        private void button_InfoManagement_Click(object sender, EventArgs e)
        {
            showSubForm(3);
        }

        private void button_CalibrationManagement_Click(object sender, EventArgs e)
        {
            showSubForm(4);
        }

        private void button_LogManagement_Click(object sender, EventArgs e)
        {
            showSubForm(5);
        }

        private void button_StopOperating_Click(object sender, EventArgs e)
        {
            showSubForm(6);
        }

        private void button_ManualOperating_Click(object sender, EventArgs e)
        {
            showSubForm(7);
        }

        private void button_FormulaConfigue_Click(object sender, EventArgs e)
        {
            showSubForm(8);
        }

        private void button_MonitorChart_Click(object sender, EventArgs e)
        {
            showSubForm(9);
        }

        private void button_ProductionChart_Click(object sender, EventArgs e)
        {
            showSubForm(10);
        }
        private void button_Help_Click(object sender, EventArgs e)
        {
            showSubForm(11);
        }
        private void button_About_Click(object sender, EventArgs e)
        {
            MessageBox.Show("北人科技，2008");
        }
        private void showSubForm(int itemp)
        {
            for (int i = 0; i < listfrm.Count; i++)
            {
                if (i == itemp)
                {
                    listfrm[i].Show();
                    continue;
                }
                listfrm[i].Hide();
            }
        }
        private void button_Logon_Logoff_Click(object sender, EventArgs e)
        {

        }

        private void button_Reset_Click(object sender, EventArgs e)
        {

        }

        private void button_Exit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }


    }
}
